package com.huang.design.creatation.prototype;

public class User implements  Cloneable{
    private  String  name;
    private  Integer age;

    //原型模式    再次获取的时候  获取克隆体   相互不会影响
    @Override
    public Object clone(){
        User user = new User();
        user.setName(this.name);
        user.setAge(this.age);
        return user;
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public User() {
        System.out.println("创建了对象");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }
}
